package com.gengzi.search.controller;


import com.gengzi.common.pojo.PageResult;
import com.gengzi.search.api.SearchControllerApi;
import com.gengzi.search.pojo.Goods;

import com.gengzi.search.pojo.SearchRequest;
import com.gengzi.search.pojo.SearchResult;
import com.gengzi.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

/**
 * @author 董诗攀
 */
@Controller
//@CrossOrigin
public class SearchController implements SearchControllerApi {

    @Autowired
    private SearchService searchService;

    /**
     * 搜索商品
     *
     * @param request
     * @return
     */
    @Override
    @PostMapping("page")
    public ResponseEntity<SearchResult> search(@RequestBody SearchRequest request){
        System.out.println(request.toString());
        SearchResult result = this.searchService.search(request);
        if (result == null || CollectionUtils.isEmpty(result.getItems())){
            System.out.println("没有搜索到数据！");
            return ResponseEntity.ok(result);
        }
        return ResponseEntity.ok(result);
    }
}